<?php

class WBCardPanel extends WBPanel { 
	public function __construct($options = array()) { 
		parent::__construct($options);
	}
	
	public function initComponent() { 
		parent::initComponent();
		
		if (!isset($this->current)) $this->setOption('current', 0);
		
		$this->setLayout('full');
		
		$this->move(0);
	}
	
	public function add($com) {
		
		$com = WBApplication::createObject($com, $this);
		
		$com->setOption('autoVisible', false);
		$com->setVisible(false);
		 
		return parent::add($com);
	}
	
	public function setCurrent($index = 0) {
		$this->setOption('current', $index); 
	}
	
	public function getCurrent() {
		return $this->getOption('current'); 
	}	
	
	public function move($index = 0) { 
		$this->setCurrent($index);
		
		$list = $this->getComponentList(true);
		
		$temp = array();
		
		foreach ($list as $i => $com) {
			$com->setVisible(($i == $index));
		}		
		
		$this->doLayout();
	}
	
	public function next() { 
		$len = $this->length();
		
		$current = $this->getOption('current')+1;
		
		$this->setCurrent($current%$len);

		$this->doLayout();
	}
	
	public function prev() { 
		$len = $this->length();
		$current = $this->getOption('current')-1;
		
		if ($current < 0) { 
			$current = $len - 1;
		}
		
		$this->setCurrent($current%$len);

		$this->doLayout();
	}
}

?>